package com.plamform.bean.springsecurity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Resuser implements Serializable, UserDetails {
    @TableId(type = IdType.AUTO)
    private Integer userid;
    private String username;
    // UserDetails接口中定义的密码字段名必须为password
    @TableField(value = "pwd")
    private String password;
    private String email;
    //表中没有该字段 用于封装角色
    @TableField(exist = false)
    private String role="user";


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 返回一个SimpleGrantedAuthority对象，表示用户的角色
        return Arrays.asList(new SimpleGrantedAuthority(role));
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;//表示账号没有过期
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;//表示账号没有被锁定
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;//表示密码没有过期
    }

    @Override
    public boolean isEnabled() {
        return true;//表示账号可用
    }
}

